import React from 'react';
import { DrawerForm } from '@ant-design/pro-form';
import { Form, Input, message } from 'antd';
import { useRequest } from 'ahooks';
import { apiSystemUsers } from '@/api/system/users.api';

interface SystemEditUserProps {
  user?: API.Users;
}

export const SystemEditUser = (props: SystemEditUserProps) => {
  const { run: submitRequest } = useRequest(apiSystemUsers.editInfo, {
    manual: true,
    onSuccess: () => {
      message.success('保存成功');
      return true;
    },
  });
  // 提交表单
  const onFormSubmit = async (data: API.Users) => {
    submitRequest(data);
  };
  return (
    <DrawerForm
      title={'修改信息'}
      trigger={<a>编辑基本信息</a>}
      initialValues={props.user}
      onFinish={onFormSubmit}
    >
      <Form.Item label={'登录名'} name={'username'}>
        <Input />
      </Form.Item>

      <Form.Item label={'显示名称'} name={'nickname'}>
        <Input />
      </Form.Item>

      <Form.Item label={'备注'} name={'remark'}>
        <Input.TextArea />
      </Form.Item>
    </DrawerForm>
  );
};
